package com.itheima.controller.backend.security;

import com.itheima.Service.CheckItemService;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/checkitem")
@RestController("backendCheckItemController")
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;

    /**
     * 新增检查项
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("新增检查项:{}",checkItem);
        checkItemService.add(checkItem);
        return new Result(true,"添加成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result del(String id){
        log.info("删除检查项:{}",id);
        checkItemService.del(id);
        return new Result(true,"删除成功");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result getById(Integer id){
        log.info("根据id查询:{}",id);
        CheckItem checkItem= checkItemService.getById(id);
        return new Result(true,"查询成功",checkItem);
    }

    /**
     * 修改检查项
     * @param checkItem
     * @return
     */
    @PostMapping("/edit")
    public Result update(@RequestBody CheckItem checkItem){
        log.info("修改检查项:{}",checkItem);
        checkItemService.update(checkItem);
        return new Result(true,"修改成功");
    }

    /**
     * 分页查询
     * @return
     */
    @PostMapping("/findPage")
    public PageResult PageQuery(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询:{}",queryPageBean);
        PageResult pageResult= checkItemService.PageQuery(queryPageBean);
        return pageResult;
    }

    /**
     * 查询所有检查项
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){
        log.info("查询所有检查项");
        List<CheckItem> checkItemList=checkItemService.getAll();
        return new Result(true,"查询所有检查项",checkItemList);
    }

    /**
     * 根据检查组id查询关联的检查项id
     * @param checkgroupId
     * @return
     */
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(String checkgroupId){
        log.info("根据检查组id查询关联的检查项id:{}",checkgroupId);
        List<Integer> integerList= checkItemService.getCheckItemIdsByCheckGroupId(checkgroupId);
        return new Result(true,"查询检查项成功",integerList);
    }

}
